package com.cskaoyan.service.wx;

import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.zxw.wx.WxFootPrintListEntityVo;
import com.cskaoyan.mapper.marketMapper.MarketFootprintMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 曾添乐啦
 * @since 2023/01/01 21:54
 */
@Service
public class WxFootPrintServiceImpl implements WxFootPrintService {

    @Autowired
    MarketFootprintMapper marketFootprintMapper;

    @Override
    public CommonData<WxFootPrintListEntityVo> selectUserAllFootprint(BasePageInfo info, Integer userId) {

        //分页插件 PageHelper，辅助我们做分页以及分页信息的获得
        //开启分页
        PageHelper.startPage(info.getPage(), info.getLimit());

        //执行查询过程中拼接分页信息
        // 如果按照page=5 limit = 10做分页，goods.size()会是多少 10
        //使用逆向工程提供的marketStorageMapper.selectByExample()方法，根据形参知需要new一个实例对象
        List<WxFootPrintListEntityVo> wxFootPrintListEntityVos = marketFootprintMapper.selectUserAllFootPrintByUserId(userId);
        //排序
        //example.createCriteria();该方法用来拼接查询条件,


        // 将查询结果作为有参构造方法的形参传入，可以获得PageInfo
        PageInfo<WxFootPrintListEntityVo> pageInfo = new PageInfo<>(wxFootPrintListEntityVos);
        CommonData commonData = CommonData.data(pageInfo);
        // list()方法不做分页的情况下可以查到的数据总量

        return commonData;

    }

    @Override
    public int deleteSelectedFootprint(Integer id) {

        int deleteAffected = marketFootprintMapper.deleteByPrimaryKey(id);

        return deleteAffected;
    }
}
